<template>
	<view class="content">
		<!-- <view class="uni-list">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in news" :key="index"
			@tap="openinfo" :data-newsid="item.post_id">
				<view class="uni-media-list">
					<image class="uni-media-list-logo" :src="item.author_avatar"></image>
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top">{{item.title}}</view>
						<view class="uni-media-list-text-bottom uni-ellipsis">{{item.created_at}}</view>
					</view>
				</view>
			</view>
		</view>
	 -->
	 
		<!-- <swiperTemp :imgUrl="imgUrl"></swiperTemp> -->
		<view class="tiaojian">
			<view :class="id==item.id?'active':''" v-for="item in xuanze" :key="item.id" @click="fresh(item.id)">
			{{item.item}}
			</view>
		</view>
		<newsListTemp :newsList="lists"></newsListTemp>

	</view>
</template>

<script>
	import newsListTemp from '../../../components/newsList-temp.vue';
	import swiperTemp from '../../../components/swiper-temp.vue';
	import global from '../../../components/tool/homePageQuery.vue';
	export default {
		components:{
			newsListTemp,
			swiperTemp
		},
		data(){
			return{
				imgUrl:[
					{"id":1,"url":"https://pic.36krcnd.com/avatar/201803/08005901/c41olcs56y2dq292.jpg!480"},
					{"id":2,"url":"http://krplus-pic.b0.upaiyun.com/201603/22055321/cg0huhoojxi0iipw.jpg!480"},
					{"id":3,"url":"https://pic.36krcnd.com/avatar/201803/08005901/c41olcs56y2dq292.jpg!480"}
				],
				id:1,
				xuanze:[{
					item:"全部",
					id:1
				},{
					item:"热点资讯",
					id:2
				},{
					item:"行业观点",
					id:3
				}],
				lists:[]
			}
		},
		onLoad:function(){
			uni.showLoading();
			/* uni.request({
				url: 'https://unidemo.dcloud.net.cn/api/news',
				method: 'GET',
				data: {},
				success: res => {
					this.lists=res.data
					console.log(res);
					uni.hideLoading()
				},
				fail: () => {},
				complete: () => {}
			}); */
			var usrtaken = uni.getStorageSync('token_key');
			var url=global.api.queryHomePageDataUrl;
			uni.request({  
				method:'POST',
				url: url, 
				header : {'content-type':'application/x-www-form-urlencoded'},
				data: {
					queryPhotoNumber: '3',//轮播图3
					queryCJKBNumber: '1',//财经快报1
					queryInformNumber:'10',//资讯2
					token:usrtaken
				},
				
				dataType:'json',
				success: (res) => {
					var code=res.data.code;
					var message=res.data.message;
					//console.log("首页轮播图以及财经快报资讯数据查询接口返回="+JSON.stringify(res.data));
					if(code=='0'){
						console.log("首页信息获取成功！");
						var imgArray = new Object();   
						imgArray = res.data.data;
						//console.log("处理后的轮播图集合############"+JSON.stringify(imgArray.photoList));
						var tempArray = new Array();
						tempArray = imgArray.photoList;
						//console.log("changdu@@@@@@@@"+tempArray.length);
						
						//财经快报模块相关操作
						var cjkbArray = new Array();
						cjkbArray = imgArray.newsList;
						//console.log("财经快报模块相关======="+JSON.stringify(cjkbArray));
						//console.log("财经快报模块长度======="+cjkbArray.length); 
						var caijinAndInforArray = new Array();
						for (var i = 0; i < cjkbArray.length; i++) {
							var cjkbItem = new Object();
							cjkbItem.summary = cjkbArray[i].bL_HeadLine;//标题
							cjkbItem.column_name = cjkbArray[i].bL_AUTHOR;//作者
							cjkbItem.post_id = cjkbArray[i].bL_ID;//ID
							cjkbItem.cover = cjkbArray[i].pIC_ADDR;//缩略图地址 
							console.log("图片财经快报URL*****"+cjkbArray[i].pIC_ADDR+cjkbArray[i].bL_ID);
							cjkbItem.views_count = cjkbArray[i].cREATE_DATEs; //评论数量改为创建时间展示
							caijinAndInforArray.push(cjkbItem);
						} 
						//资讯模块处理  
						var inforArray = new Array();
						inforArray = imgArray.inforList;
						console.log("资讯模块相关======="+JSON.stringify(inforArray));
						console.log("资讯模块长度======="+inforArray.length); 
						for (var i = 0; i < inforArray.length; i++) {
							var zxItem = new Object();
							zxItem.summary = inforArray[i].news_Tit;//标题
							zxItem.column_name = inforArray[i].news_Typ;//作者更改为展示资讯类型
							zxItem.post_id = inforArray[i].news_Id;//ID
							zxItem.cover = inforArray[i].thumb_Pic;//缩略图地址
							console.log("资讯模块URL*****"+inforArray[i].thumb_Pic);
							zxItem.views_count = inforArray[i].create_DateString; //评论数量更改为展示创建时间
							caijinAndInforArray.push(zxItem); 
						} 
						this.lists = caijinAndInforArray;
						uni.hideLoading()
					}else{
						uni.showToast({
						title:message,
						icon:"none"
						});
						return false;
					}
					
				},fail:(res) => {
					/* console.log("fail");
					console.log(res.data); */
				},complete:(res) => {
					/* console.log("complete");
					console.log(res.data); */
				}
			});
			
		},
		methods:{
			openinfo(e){
				
				var newsid=e.currentTarget.dataset.newsid
				uni.navigateTo({
					url:'info/info?newsid='+newsid
				})
			},
			
				fresh(id){
					this.id=id
				}
			
		}
	}
</script>

<style>
.tiaojian{
	display: flex;
	flex-direction: row;
	background: #FFFFFF;
	height: 70upx;
	align-items: center;
	text-align: center;
	justify-content: space-around;
	margin-top: 20upx;
	padding-bottom: 3px;
	}
.tiaojian view{
	
	line-height: 70upx;
	color: #999999;
	
}
.tiaojian .active{
	border-bottom: 3px solid #c49c5a;
	color:  #c49c5a;
}
</style>
